This example demonstrates how to create a filtered dropdown selection list (FilterListCode) which, when a user starts typing, only displays the relevant options.
We first need a rulebase that uses a dropdown list to collect an attribute value during an investigation.
the person is eligible if
the person's profession = "IT"
We now modify the Velocity templates to add the filtering functionality. The filtered dropdown list (also called a combo-box) is created by using the existing Web Determinations template DropdownSelection.vm found under templates/investigation.
Note: Combo box search functionality is unsupported in Opera browsers and hence disabled.
The effect is achieved by using an input field along with the dropdown list. We show or hide the dropdown list based on where the focus is on the page. The user can use the collapse and expand icons to access the dropdown list from the input field; for example, if a user is typing in the input text field, then the dropdown list is shown. This list shown will only have the options that match the text in the input field. If the user clicks anywhere else other than the expand/collapse icons, the dropdown list will be made invisible.
The files can be found under examples\web-determinations\filtered-list-control\src\templates. The customization consists of the following files:
File |
Description |
---|---|
templates/investigation/Dropdown-selection.vm | Contains the layout of the input text field and the dropdown list that make up a combo-box. |
templates/javascript/comboBox.js | Contains the code for the combo-box effect. |
templates/javascript/onClick.vm |
Contains the code for handling the visibility of the dropdown selection based on where the user clicks on the page. |
templates/javascript/filter.js | Contains the code for filtering a list of options based on some text. |
templates/question_screen.vm |
Modified to include the javascript files. |
To run the example, do the following: